package com.zhongxiangspace.controller;

import com.zhongxiangspace.entity.Entrust;
import com.zhongxiangspace.result.ExceptionResult;
import com.zhongxiangspace.result.NormalResult;
import com.zhongxiangspace.result.Result;
import com.zhongxiangspace.service.EntrustService;
import com.zhongxiangspace.tools.DateUtil;
import com.zhongxiangspace.tools.MessageCaptchaUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class EntrustController {
    @Autowired
    private EntrustService entrustService;

    @ResponseBody
    @PostMapping({"/lists/entrustfindhouse.do"})
    private Result entrustfindhouse(Entrust entrust, HttpServletRequest request, HttpServletResponse response) {
        try {
            entrust.setCreate_time(DateUtil.getDateTime());
            entrust.setModify_time(DateUtil.getDateTime());
            entrust.setEntrust_type("委托找房");
            entrust.setReferrer(request.getHeader("Referer"));
            boolean falg = this.entrustService.insert(entrust);
            if (falg == true) {
                MessageCaptchaUtil.sund(entrust.getPhone());
            }
            return new NormalResult(Boolean.valueOf(falg));
        } catch (Exception e) {
            return new ExceptionResult(e);
        }
    }

    @ResponseBody
    @PostMapping({"/lists/putthehouse.do"})
    private Result putthehouse(Entrust entrust, HttpServletRequest request) {
        try {
            entrust.setCreate_time(DateUtil.getDateTime());
            entrust.setModify_time(DateUtil.getDateTime());
            entrust.setEntrust_type("投放房源");
            entrust.setReferrer(request.getHeader("Referer"));
            boolean falg = this.entrustService.insert(entrust);
            if (falg == true) {
                MessageCaptchaUtil.sund(entrust.getPhone());
            }
            return new NormalResult(Boolean.valueOf(falg));
        } catch (Exception e) {
            return new ExceptionResult(e);
        }
    }

    @ResponseBody
    @PostMapping({"/lists/appoint.do"})
    private Result appoint(Entrust entrust, HttpServletRequest request) {
        try {
            entrust.setCreate_time(DateUtil.getDateTime());
            entrust.setModify_time(DateUtil.getDateTime());
            entrust.setEntrust_type("立即预约");
            entrust.setReferrer(request.getHeader("Referer"));
            boolean falg = this.entrustService.insert(entrust);
            if (falg) {
                MessageCaptchaUtil.sund(entrust.getPhone());
            }
            return new NormalResult(Boolean.valueOf(falg));
        } catch (Exception var4) {
            return new ExceptionResult(var4);
        }
    }
}
